//index.js 获取应用实例
const app = getApp()
const util = require('../../utils/util.js')
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    winWidth: '',
    winHeight: '',
    code: '',
    encryptedData: '',
    iv: '',
    sessionId: '',
    setps: '',
    userm: '',
    date: '',
    usertype: false,
    adds: {},
    myadd: '',
    sport: {},
    minqw: '0',
    maxqw: '0',
    array: 0,
    arrays: '',
    animationData: {},
    bgimage: '/image/bg.jpg',
    canvass: false,
    pageinfo: {},
    btnType: true,
    openid: ''
    // hacker: "hacker"
  },

  onShow: function () {
  },
  getUserInfos: function (e) {
    wx.switchTab({
      url: '/pages/index/index',
    })

  },

  //事件处理函数
  onReady: function (e) { },
  onLoad: function (e) {
    // util.showLogin('正在加载')
    // wx.showLoading({
    //   title: '加载中'
    // })
    wx.cloud.init()
    wx.cloud.callFunction({
      name: 'getUserInfo',
    }).then(
      res => {
        console.log(res)
        this.setData({
          openid: res.result.openId
        })
        wx.getSetting({
          success: (res) => {
            console.log(res)
            if (res.authSetting['scope.userInfo']) {
              console.log("11")
              wx.switchTab({
                url: '../index/index'
              })
            }
          }
        })
      }
    )



    wx.getSystemInfo({
      success: res => {
        wx.setStorageSync('w', res.windowWidth)
        wx.setStorageSync('y', res.windowHeight)
        this.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        })
      }
    })
  },


  onShareAppMessage: function (res) {
    return {
      title: wx.getStorageSync('username') + '今天走了' + this.data.userm + '米,不服来战！',
      path: '/pages/index/index',
      // imageUrl: wx.getStorageSync('titleimg'),
      imageUrl: '/image/title.jpg',
      success: function (res) {
        console.log(wx.getStorageSync('m'))
        // 转发成功
        wx.showModal({
          title: 'LMOMO的程序提示',
          content: '感谢您的转发，以后可以和你的好友进行PK、打卡朋友圈了！',
          success: function (res) {
            if (res.confirm) { } else if (res.cancel) {
              // console.log('用户点击取消')
            }
          }
        })
      },
      fail: function (res) {
        // 转发失败
      }
    }
  }
})